package com.mojian.mapper;

import com.mojian.entity.SysZb;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 招标 Mapper接口
 */
@Mapper
public interface SysZbMapper extends BaseMapper<SysZb> {


    /**
     * 查询招标列表
     *
     * @param sysZb 招标
     * @return 招标集合
     */
    public List<SysZb> selectZbList(SysZb sysZb);

    @Select("SELECT zb.id,zb.user_id,zb.zbbt,zb.zbwj,zb.zbms,zb.STATUS,zb.ksrq,zb.jsrq,zb.create_time,@zb.update_time,ifnull(tb.tbcs,0) tbcs " +
            "FROM sys_zb zb " +
            "LEFT JOIN (" +
            "SELECT tb.zbid,tb.user_id,COUNT(1) tbcs FROM sys_tb tb " +
            "INNER JOIN sys_user u ON tb.user_id=u.id WHERE tb.user_id= #{userid} GROUP BY tb.zbid,tb.user_id" +
            ") tb ON zb.id=tb.zbid " +
            "WHERE zb.ksrq<=CURDATE() AND zb.jsrq>=CURDATE() AND zb.STATUS='1'")
    List<Map<String, Object>> selectZBZList(@Param("userid") Long userid);

}
